<?php
if (!defined("_INDEX")) { header("Location: /"); die; }

if ($route->GET("city"))
{
	$city = urldecode($route->GET("city"));
	
	$str = "[";
	$result = $db->getCell("select `name` from `city` where INSTR(`name`, '$city') = 1 order by `name` limit 1");
	if ($result != "")
		$result = substr_replace($result,$city,0,strlen($city));
	$str .= "{\"tip\":\"$result\"}";
	$result = $db->getColumn("select `name` from `city` where `name` like '$city%' order by `name`");
	if (count($result) > 0)
	{
		$str .= ",{\"name\":\"";
		$str .= implode("\"},{\"name\":\"",$result);
		$str .= "\"}";
	}
	$str .= "]";
	echo $str;
}
else
{
	$str = "[{\"tip\":\"\"}";
	$result = $db->getColumn("select `name` from `city` order by `name`");
	if (count($result) > 0)
	{
		$str .= ",{\"name\":\"";
		$str .= implode("\"},{\"name\":\"",$result);
		$str .= "\"}";
	}
	$str .= "]";
	echo $str;
}
?>